//
//  WKLoginViewController.m
//  WKMaybell
//
//  Created by 何文虎 on 2019/1/15.
//  Copyright © 2019 何文虎. All rights reserved.
//

#import "WKLoginViewController.h"
#import "WKRegisterView.h"
#import "WKLoginView.h"
#import "LGChangeTitleView.h"
#import "WKRegistViewController.h"

@interface WKLoginViewController ()<UIScrollViewDelegate,JXCategoryViewDelegate>
{
    WKLoginView *_loginView;
    WKRegisterView *_registerView;
}
@property(nonatomic,strong)UIScrollView *scrollView;
@property(nonatomic,strong)JXCategoryTitleView *categoryView;
@end

@implementation WKLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    [self initViews];
    [self setUpAllViewController];
}

- (void)initViews{
    
    CGFloat bgimg_height = 140+NavBarHeight;
    LGChangeTitleView *titleView = [[LGChangeTitleView alloc]initWithFrame:CGRectMake(31, bgimg_height, 130, 43)];
    [self.view addSubview:titleView];
    
    CGFloat login_top = bgimg_height+43;
    _loginView = [[WKLoginView alloc]initWithFrame:CGRectMake(0, login_top, ScreenWidth, ScreenHeight-login_top)];
    [self.view addSubview:_loginView];
    _registerView = [[WKRegisterView alloc]initWithFrame:CGRectMake(0, login_top, ScreenWidth, ScreenHeight-login_top)];
    [self.view addSubview:_registerView];
    
   
    
}


- (void)setUpAllViewController{
   
    CGFloat bgimg_height = 140+NavBarHeight;
    CGFloat login_top = bgimg_height+43;
    
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, login_top, ScreenWidth, ScreenHeight-login_top)];
    self.scrollView.delegate = self;
    self.scrollView.pagingEnabled = YES;
    self.scrollView.contentSize = CGSizeMake(ScreenWidth*2, 0);
    self.scrollView.bounces = NO;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:self.scrollView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [self.scrollView addGestureRecognizer:tap];
    [self.view addGestureRecognizer:tap];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    if (@available(iOS 11.0, *)) {
        self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    _loginView = [[WKLoginView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-login_top)];
    [self.scrollView addSubview:_loginView];
    _registerView = [[WKRegisterView alloc]initWithFrame:CGRectMake(ScreenWidth, 0, ScreenWidth, ScreenHeight-login_top)];
    [self.scrollView addSubview:_registerView];
    
    self.categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, bgimg_height, 130, 43)];
    self.categoryView.titles = @[@"登录",@"注册"];
    self.categoryView.backgroundColor = [UIColor whiteColor];
    self.categoryView.delegate = self;
    self.categoryView.titleSelectedColor = UIColorFromHex(0x3C3C3C);
    self.categoryView.titleColor = UIColorFromHex(0x979797);
    self.categoryView.titleFont = HEBoldFont(16);
    self.categoryView.titleColorGradientEnabled = NO;
    self.categoryView.titleLabelZoomEnabled = YES;
    
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.indicatorLineViewColor = BACK_COLOR;
    lineView.indicatorLineWidth = 6;
    lineView.indicatorLineViewHeight = 6;
    lineView.indicatorLineViewCornerRadius = 3;
    self.categoryView.indicators = @[lineView];
    self.categoryView.contentScrollView = self.scrollView;
    
    //    [self.categoryView addSubview:[WHFactory addLineWithFrame:CGRectMake(0, 43, ScreenWidth, 1)]];
    
    [self.view addSubview:self.categoryView];
    
    
    @weakify(self);
    _registerView.registBlock = ^{
        @strongify(self);
        WKRegistViewController *registVC = [[WKRegistViewController alloc]init];
        [self presentViewController:registVC animated:YES completion:nil];
        
    };
    
}

#pragma mark - 点击收键盘
- (void)tapAction:(UITapGestureRecognizer*)tap{
    [_loginView HiddenKeyBar];
}






/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
